<% content_for :page_title do %>
  <%= plural_resource_name(Spree::ShippingMethod) %>
<% end %>

<% content_for :page_actions do %>
  <%= button_link_to Spree.t(:new_shipping_method), new_object_url,  class: "btn-success", icon: 'add.svg', id: 'admin_new_shipping_method_link' %>
<% end if can? :create, Spree::ShippingMethod %>

<% if @shipping_methods.any? %>
<div class="table-responsive">
  <table class="table" id='listing_shipping_methods'>
    <thead>
      <tr data-hook="admin_shipping_methods_index_headers">
        <th><%= Spree.t(:name) %></th>
        <th><%= Spree.t(:zone) %></th>
        <th><%= Spree.t(:calculator) %></th>
        <th class="text-center"><%= Spree.t(:display) %></th>
        <th data-hook="admin_shipping_methods_index_header_actions" class="actions"></th>
      </tr>
    </thead>
    <tbody>
      <% @shipping_methods.includes(:zones, :calculator).each do |shipping_method| %>
        <tr id="<%= spree_dom_id shipping_method %>" data-hook="admin_shipping_methods_index_rows">
          <td><%= shipping_method.admin_name + ' / ' if shipping_method.admin_name.present? %><%= shipping_method.name %></td>
          <td>
            <% shipping_method.zones.each do |zone| %>
              <%= link_to zone.name, spree.edit_admin_zone_path(zone) %>
            <% end %>
          </td>
          <td><%= shipping_method.calculator.description %></td>
          <td class="text-center"><%= shipping_method.display_on.blank? ? Spree.t(:none) : Spree.t(shipping_method.display_on) %></td>
          <td data-hook="admin_shipping_methods_index_row_actions" class="actions actions-2 text-right">
            <%= link_to_edit(shipping_method, no_text: true) if can? :edit, shipping_method %>
            <%= link_to_delete(shipping_method, no_text: true) if can? :delete, shipping_method %>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
</div>
<% else %>
  <div class="alert alert-info no-objects-found">
    <%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::ShippingMethod)) %>,
    <%= link_to(Spree.t(:add_one), new_object_url) if can? :create, Spree::PaymentMethod %>!
  </div>
<% end %>
